var fun1 = function(name) {
	print('Hi there from Javascript, ' + name);
	return "greetings from javascript";
};
var fun2 = function(object) {
	print("JS Class Definition: " + Object.prototype.toString.call(object));
};


var callJava = function() {
	var NashornDemo = Java.type('com.zzy.js.NashornDemo');
	var result = NashornDemo.javaFunc('John Doe');
	print(result);
	return "这是结果";
};


function Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.getFullName = function() {
        return this.firstName + " " + this.lastName;
    }
}

var person1 = new Person("Peter2", "Parker");

var callJavaParam = function() {
	var NashornDemo = Java.type('com.zzy.js.NashornDemo');
	var result = NashornDemo.javaFuncParam(person1);
	print(result);
	return "这是结果2";
};



var javaCollection = function() {
	var ArrayList = Java.type('java.util.ArrayList');
	var list = new ArrayList();
	list.add('a');
	list.add('b');
	list.add('c');
	
    list.stream()
    .filter(function(el) {
        return el.startsWith("aaa");
    })
    .sorted()
    .forEach(function(el) {
        print(el);
    });
	
	var map = new java.util.HashMap();
	map.put('foo', 'val1');
	map.put('bar', 'val2');
	
};


var loadJs = function() {
	load('http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js');
	var odds = _.filter([1, 2, 3, 4, 5, 6], function (num) {
	    return num % 2 == 1;
	});
	print(odds); 
};




